﻿using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace System
{
    /// <summary>
    /// 日志辅助类
    /// <para>2010/8/14</para>
    /// 	<para>THINKPADT61</para>
    /// 	<para>tangjingbo</para>
    /// </summary>
    public static class LogHelper
    {
        /// <summary>
        /// Infoes the specified p.
        /// </summary>
        /// <param name="p">The p.</param>
        public static void Info(string p)
        {
            Logger.Writer.Info(p);
        }

        /// <summary>
        /// Errors the specified p.
        /// </summary>
        /// <param name="p">The p.</param>
        public static void Error(string p)
        {
            Logger.Writer.Warn(p);
        }

        #region Nested type: Category

        /// <summary>
        /// 日志类别
        /// <para>2010/8/14</para>
        /// 	<para>THINKPADT61</para>
        /// 	<para>tangjingbo</para>
        /// </summary>
        public static class Category
        {
            /// <summary>
            /// 业务信息
            /// </summary>
            public static string BusinessInfo = "BusinessInfo";

            /// <summary>
            /// 系统错误
            /// </summary>
            public static string BusinessError = "BusinessError";
        }

        #endregion

        #region 日志扩展

        /// <summary>
        /// Infoes the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="messageFormat">The message format.</param>
        /// <param name="args">The args.</param>
        public static void Info(this LogWriter writer, string messageFormat, params Object[] args)
        {
            string message = string.Format(messageFormat, args);
            writer.Write(new LogEntry(message, Category.BusinessInfo, 100, 1000, TraceEventType.Information, message,
                                      null));
        }

        /// <summary>
        /// Infoes the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="message">The message.</param>
        public static void Info(this LogWriter writer, string message)
        {
            writer.Write(new LogEntry(message, Category.BusinessInfo, 100, 1000, TraceEventType.Information, message,
                                      null));
        }

        /// <summary>
        /// Warns the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="message">The message.</param>
        public static void Warn(this LogWriter writer, string message)
        {
            writer.Write(new LogEntry(message, Category.BusinessError, 100, 1000, TraceEventType.Warning, "业务信息", null));
        }

        /// <summary>
        /// Warns the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="messageFormat">The message format.</param>
        /// <param name="args">The args.</param>
        public static void Warn(this LogWriter writer, string messageFormat, params object[] args)
        {
            string message = string.Format(messageFormat, args);
            writer.Write(new LogEntry(message, Category.BusinessError, 100, 1000, TraceEventType.Warning, "系统错误", null));
        }

        #endregion
    }
}